import React, {useEffect, useState} from 'react'
import BatchUpload from '@/components/BatchUpload'
import {getData, getIReturnCar, postIReturnCar} from '@/service/order/index'

function ReturnCar(props: any) {
	const {info, sunchange, getOrderList} = props
	const [importReturnCarItem, setImportReturnCarItem] = useState(false) // 导入退车费用项
	const [deduction, setDeduction] = useState<any>([]) // 扣款费用项
	const [reduction, setReduction] = useState<any>([]) // 减免费用项
	useEffect(() => {
		setImportReturnCarItem(info)
	}, [info])
	const childCange = (value: any) => {
		if (sunchange) {
			sunchange(value)
		}
	}
	const getRetrunValue = (value: any) => {
		const list1 = value[0]?.collectList
		const list2 = value[0]?.deductionList
		const list3: any = []
		const list4: any = []
		if (list1) {
			list1?.forEach((item: any) => {
				const obj = {
					title: item?.feeItemName,
					dataIndex: item?.feeItemName,
					align: 'center',
					key: item?.feeItemName,
					width: 100,
				}
				list3.push(obj)
			})
			const obj1 = {
				title: '合计',
				dataIndex: 'collectAll',
				align: 'center',
				key: 'collectAll',
				width: 100,
			}
			list3.push(obj1)
		}
		setDeduction(list3)
		if (list2) {
			list2?.forEach((item: any) => {
				const obj = {
					title: item?.feeItemName,
					dataIndex: item?.feeItemName,
					align: 'center',
					key: item?.feeItemName,
					width: 100,
				}
				list4.push(obj)
			})
			const obj2 = {
				title: '合计',
				dataIndex: 'dedluctALL',
				align: 'center',
				key: 'dedluctALL',
				width: 100,
			}
			list4.push(obj2)
			setReduction(list4)
		}
	}
	const column = [
		{
			title: '订单编号',
			dataIndex: 'orderCarNo',
			align: 'center',
			key: 'orderCarNo',
			width: 200,
		},
		{
			title: '司机名称',
			dataIndex: 'driverName',
			align: 'center',
			key: 'driverName',
			width: 100,
		},
		{
			title: '车牌号',
			dataIndex: 'plateNo',
			align: 'center',
			key: 'plateNo',
			width: 100,
		},
		{
			title: '扣款费用项',
			dataIndex: 'platformDriverNo',
			align: 'center',
			key: 'platformDriverNo',
			width: 200,
			children: deduction,
		},
		{
			title: '减免费用项',
			dataIndex: 'platformDriverNo',
			align: 'center',
			key: 'platformDriverNo',
			width: 200,
			children: reduction,
		},
		{
			title: '退还',
			dataIndex: 'paymentCount',
			align: 'center',
			key: 'paymentCount',
			width: 100,
			render: (text: any) => <span>{text.toFixed(2)}</span>,
		},
		{
			title: '补缴',
			dataIndex: 'retrunCount',
			align: 'center',
			key: 'retrunCount',
			width: 100,
			render: (text: any) => <span>{text.toFixed(2)}</span>,
		},
		{
			title: '状态',
			dataIndex: 'resultMsg',
			align: 'center',
			key: 'resultMsg',
			width: 200,
			fixed: 'right',
		},
	]
	return (
		<BatchUpload
			isModalOpen={importReturnCarItem}
			setIsModalOpen={setImportReturnCarItem}
			importData={getIReturnCar} // 导入接口
			onTableList={getData} // 获取列表数据-失败
			getListData={getOrderList} // 获取列表数据-成功
			columns={column}
			sourceId={40}
			templateType="退车费用项导入"
			uploadFileUrl={postIReturnCar} // 文件上传接口
			title="退车费用项导入"
			width={800}
			getRetrunValue={getRetrunValue}
			childCange={childCange}
			childState={2}
		/>
	)
}

export default ReturnCar
